From 4abf27e7b5c1a00e064db4bbee9dca501a37ccd1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 15 Jul 2014 17:51:49 -0700 Subject: [PATCH] Bootstrap cargo with cargo --- .gitmodules | 9 ---- Cargo.toml | 71 ++++++++++++++++++++++++++ Makefile | 94 ++++++++--------------------------- libs/hamcrest-rust | 1 - libs/hammer.rs | 1 - libs/toml-rs | 1 - src/bin/cargo-run.rs | 1 - src/bin/cargo.rs | 2 +- src/etc/dl-snapshot.py | 48 ++++++++++++++++++ src/{ => etc}/install.sh | 0 src/etc/print-new-snapshot.py | 23 +++++++++ src/snapshots.txt | 4 ++ tests/support/mod.rs | 2 +- tests/test_cargo_compile.rs | 7 +-- 14 files changed, 173 insertions(+), 91 deletions(-) delete mode 100644 .gitmodules create mode 100644 Cargo.toml delete mode 160000 libs/hamcrest-rust delete mode 160000 libs/hammer.rs delete mode 160000 libs/toml-rs create mode 100644 src/etc/dl-snapshot.py rename src/{ => etc}/install.sh (100%) create mode 100644 src/etc/print-new-snapshot.py create mode 100644 src/snapshots.txt diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index a433e13d2..000000000 --- a/.gitmodules +++ /dev/null @@ -1,9 +0,0 @@ -[submodule "libs/hammer.rs"] - path = libs/hammer.rs - url = https://github.com/wycats/hammer.rs.git -[submodule "libs/hamcrest-rust"] - path = libs/hamcrest-rust - url = https://github.com/carllerche/hamcrest-rust/ -[submodule "libs/toml-rs"] - path = libs/toml-rs - url = https://github.com/alexcrichton/toml-rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..e13a0ee62 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,71 @@ +[project] + +name = "cargo" +version = "0.0.1-pre" +authors = ["Yehuda Katz ", + "Carl Lerche "] + +[[lib]] + +name = "cargo" +path = "src/cargo/lib.rs" + +# TODO: remove all these `rev` markers once we have an official lockfile +[dependencies.hammer] +git = "https://github.com/wycats/hammer.rs" +rev = "c085c639" + +[dependencies.toml] +git = "https://github.com/alexcrichton/toml-rs" +rev = "a3c7f2c3" + +[dependencies.hamcrest] +git = "https://github.com/carllerche/hamcrest-rust.git" +rev = "05acf768" + +[[bin]] +name = "cargo" +test = false + +[[bin]] +name = "cargo-build" +test = false + +[[bin]] +name = "cargo-clean" +test = false + +[[bin]] +name = "cargo-git-checkout" +test = false + +[[bin]] +name = "cargo-read-manifest" +test = false + +[[bin]] +name = "cargo-run" +test = false + +[[bin]] +name = "cargo-rustc" +test = false + +[[bin]] +name = "cargo-test" +test = false + +[[bin]] +name = "cargo-verify-project" +test = false + +[[bin]] +name = "cargo-version" +test = false + +[[bin]] +name = "cargo-new" +test = false + +[[test]] +name = "tests" diff --git a/Makefile b/Makefile index 548b61d85..e89e044fa 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,5 @@ -RUSTC_FLAGS ?= DESTDIR ?= PREFIX ?= /usr/local -TARGET ?= target PKG_NAME ?= cargo-nightly ifeq ($(wildcard rustc/bin),) @@ -24,98 +22,49 @@ export CFG_VERSION export PATH := $(CURDIR)/rustc/bin:$(PATH) -# Link flags to pull in dependencies -BINS = cargo \ - cargo-build \ - cargo-clean \ - cargo-read-manifest \ - cargo-rustc \ - cargo-verify-project \ - cargo-git-checkout \ - cargo-test \ - cargo-run \ - cargo-version \ - cargo-new - -SRC = $(shell find src -name '*.rs' -not -path 'src/bin*') - ifeq ($(OS),Windows_NT) X = .exe endif -DEPS = -L libs/hammer.rs/target -L libs/toml-rs/build -TOML = libs/toml-rs/build/$(shell $(RUSTC) --print-file-name libs/toml-rs/src/toml.rs) -HAMMER = libs/hammer.rs/target/$(shell $(RUSTC) --crate-type=lib --print-file-name libs/hammer.rs/src/hammer.rs) -HAMCREST = libs/hamcrest-rust/target/libhamcrest.timestamp -LIBCARGO = $(TARGET)/libcargo.rlib -TESTDIR = $(TARGET)/tests +TARGET = target DISTDIR = $(TARGET)/dist PKGDIR = $(DISTDIR)/$(PKG_NAME) -BIN_TARGETS = $(BINS:%=$(TARGET)/%$(X)) - -all: $(BIN_TARGETS) - -# === Dependencies - -$(HAMMER): $(wildcard libs/hammer.rs/src/*.rs) - $(MAKE) -C libs/hammer.rs - -$(TOML): $(wildcard libs/toml-rs/src/*.rs) - $(MAKE) -C libs/toml-rs - -$(HAMCREST): $(shell find libs/hamcrest-rust/src/hamcrest -name '*.rs') - $(MAKE) -C libs/hamcrest-rust - -$(TARGET)/: - mkdir -p $@ - -$(TESTDIR)/: - mkdir -p $@ -# === Cargo +BIN_TARGETS := $(wildcard src/bin/*.rs) +BIN_TARGETS := $(BIN_TARGETS:src/bin/%.rs=%) +BIN_TARGETS := $(filter-out cargo,$(BIN_TARGETS)) +BIN_TARGETS := $(BIN_TARGETS:%=$(TARGET)/%$(X)) -$(LIBCARGO): $(SRC) $(HAMMER) $(TOML) | $(TARGET)/ - $(RUSTC) $(RUSTC_FLAGS) $(DEPS) --out-dir $(TARGET) src/cargo/lib.rs +CARGO := $(TARGET)/snapshot/cargo-nightly/bin/cargo$(X) -libcargo: $(LIBCARGO) +all: $(CARGO) + $(CARGO) build $(ARGS) -# === Commands +$(CARGO): src/snapshots.txt + python src/etc/dl-snapshot.py + touch $@ -$(BIN_TARGETS): $(TARGET)/%$(X): src/bin/%.rs $(HAMMER) $(TOML) $(LIBCARGO) - $(RUSTC) $(RUSTC_FLAGS) $(DEPS) -L$(TARGET) --out-dir $(TARGET) $< # === Tests -TEST_SRC = $(shell find tests -name '*.rs') -TEST_DEPS = $(DEPS) -L libs/hamcrest-rust/target +test: test-unit style no-exes -$(TESTDIR)/test-integration: $(HAMCREST) $(TEST_SRC) $(BIN_TARGETS) | $(TESTDIR)/ - $(RUSTC) --test $(TEST_DEPS) -L$(TARGET) -o $@ tests/tests.rs - -$(TESTDIR)/test-unit: $(TOML) $(HAMCREST) $(SRC) $(HAMMER) | $(TESTDIR)/ - $(RUSTC) --test -g $(RUSTC_FLAGS) $(TEST_DEPS) -o $@ src/cargo/lib.rs - -test-unit: $(TESTDIR)/test-unit - $< $(only) - -test-integration: $(TESTDIR)/test-integration - $< $(only) - -test: test-unit test-integration style no-exes +test-unit: $(CARGO) + $(CARGO) test $(only) style: sh tests/check-style.sh no-exes: - find $$(git ls-files | grep -v '^lib') -perm +111 -type f \ + find $$(git ls-files) -perm +111 -type f \ -not -name '*.sh' -not -name '*.rs' | grep '.*' \ && exit 1 || exit 0 -clean: - rm -rf $(TARGET) +# === Misc clean-all: clean - git submodule foreach make clean +clean: + rm -rf $(TARGET) dist: $(DISTDIR)/$(PKG_NAME).tar.gz @@ -133,15 +82,14 @@ distcheck: dist $(DISTDIR)/$(PKG_NAME).tar.gz: $(PKGDIR)/lib/cargo/manifest.in tar -czvf $@ -C $(DISTDIR) $(PKG_NAME) -$(PKGDIR)/lib/cargo/manifest.in: $(BIN_TARGETS) Makefile +$(PKGDIR)/lib/cargo/manifest.in: all rm -rf $(PKGDIR) mkdir -p $(PKGDIR)/bin $(PKGDIR)/lib/cargo cp $(TARGET)/cargo$(X) $(PKGDIR)/bin cp $(BIN_TARGETS) $(PKGDIR)/lib/cargo - rm $(PKGDIR)/lib/cargo/cargo$(X) (cd $(PKGDIR) && find . -type f | sed 's/^\.\///') \ > $(DISTDIR)/manifest-$(PKG_NAME).in - cp src/install.sh $(PKGDIR) + cp src/etc/install.sh $(PKGDIR) cp README.md LICENSE-MIT LICENSE-APACHE $(PKGDIR) cp LICENSE-MIT $(PKGDIR) mv $(DISTDIR)/manifest-$(PKG_NAME).in $(PKGDIR)/lib/cargo/manifest.in @@ -150,7 +98,7 @@ install: $(PKGDIR)/lib/cargo/manifest.in $(PKGDIR)/install.sh --prefix=$(PREFIX) --destdir=$(DESTDIR) # Setup phony tasks -.PHONY: all clean distclean test test-unit test-integration libcargo style +.PHONY: all clean test test-unit style # Disable unnecessary built-in rules .SUFFIXES: diff --git a/libs/hamcrest-rust b/libs/hamcrest-rust deleted file mode 160000 index 05acf7681..000000000 --- a/libs/hamcrest-rust +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 05acf7681ab28198e5d7c1cc9561195de02d8d2a diff --git a/libs/hammer.rs b/libs/hammer.rs deleted file mode 160000 index c085c639a..000000000 --- a/libs/hammer.rs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c085c639ac06909301707721b174e83f40bbac70 diff --git a/libs/toml-rs b/libs/toml-rs deleted file mode 160000 index a3c7f2c38..000000000 --- a/libs/toml-rs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a3c7f2c38ef795ad34e225ca54fa6bf625e8a842 diff --git a/src/bin/cargo-run.rs b/src/bin/cargo-run.rs index 024b5df26..ee017c51e 100644 --- a/src/bin/cargo-run.rs +++ b/src/bin/cargo-run.rs @@ -1,4 +1,3 @@ -#![crate_name = "cargo-run"] #![feature(phase)] #[phase(plugin, link)] diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 81c5cc13b..824daae8f 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -105,7 +105,7 @@ fn execute() { fn process(args: Vec) -> (String, Vec) { let mut args = Vec::from_slice(args.tail()); - let head = args.shift().unwrap_or("--help".to_string()); + let head = args.remove(0).unwrap_or("--help".to_string()); (head, args) } diff --git a/src/etc/dl-snapshot.py b/src/etc/dl-snapshot.py new file mode 100644 index 000000000..eb8b5cb38 --- /dev/null +++ b/src/etc/dl-snapshot.py @@ -0,0 +1,48 @@ +import distutils.spawn +import hashlib +import os +import subprocess +import sys +import tarfile + +f = open('src/snapshots.txt') +lines = f.readlines() + +date = lines[0] +mac = lines[1] +linux = lines[2] +win = lines[3] + +if 'linux' in sys.platform: + me = linux +elif sys.platform == 'win32': + me = win +elif sys.platform == 'darwin': + me = mac +else: + raise Exception("no snapshot for the platform: " + sys.platform) + +platform, hash = me.strip().split(' ') + +tarball = 'cargo-nightly-' + platform + '.tar.gz' +url = 'http://static.rust-lang.org/cargo-dist/' + date.strip() + '/' + tarball +dl_path = "target/dl/" + tarball +dst = "target/snapshot" + +if not os.path.isdir('target/dl'): + os.makedirs('target/dl') + +ret = subprocess.call(["curl", "-o", dl_path, url]) +if ret != 0: + raise Exception("failed to fetch url") +h = hashlib.sha1(open(dl_path, 'rb').read()).hexdigest() +if h != hash: + raise Exception("failed to verify the checksum of the snapshot") + +tar = tarfile.open(dl_path) +for p in tar.getnames(): + name = p.replace("cargo-nightly/", "", 1) + fp = os.path.join(dst, name) + print("extracting " + p) + tar.extract(p, dst) +tar.close() diff --git a/src/install.sh b/src/etc/install.sh similarity index 100% rename from src/install.sh rename to src/etc/install.sh diff --git a/src/etc/print-new-snapshot.py b/src/etc/print-new-snapshot.py new file mode 100644 index 000000000..f6b3fe04f --- /dev/null +++ b/src/etc/print-new-snapshot.py @@ -0,0 +1,23 @@ +# When updating snapshots, run this file and pipe it into `src/snapshots.txt` +import os +import subprocess +import sys +import hashlib + +date = sys.argv[1] + +print(date) + +if not os.path.isdir('target/dl'): + os.makedirs('target/dl') + +snaps = ['mac', 'linux', 'win'] +for snap in snaps: + tarball = 'cargo-nightly-' + snap + '.tar.gz' + url = 'http://static.rust-lang.org/cargo-dist/' + date + '/' + tarball + dl_path = "target/dl/" + tarball + ret = subprocess.call(["curl", "-s", "-o", dl_path, url]) + if ret != 0: + raise Exception("failed to fetch url") + h = hashlib.sha1(open(dl_path, 'rb').read()).hexdigest() + print(' ' + snap + ' ' + h) diff --git a/src/snapshots.txt b/src/snapshots.txt new file mode 100644 index 000000000..3b0618d14 --- /dev/null +++ b/src/snapshots.txt @@ -0,0 +1,4 @@ +2014-07-26 + mac 9a78815c7fcdb1cdabc93eb120f80444f209d968 + linux b38e7c45292d2cc6a1932fa9a1f349f9b92c0c1d + win 4e955f8b80684ea6c9ca2dd6e2c235ce2d9cf21f diff --git a/tests/support/mod.rs b/tests/support/mod.rs index e9c8c9e44..07060671c 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -216,7 +216,7 @@ impl ErrMsg for Result { // Path to cargo executables pub fn cargo_dir() -> Path { os::getenv("CARGO_BIN_PATH").map(Path::new) - .or_else(|| os::self_exe_path().map(|p| p.dir_path())) + .or_else(|| os::self_exe_path()) .unwrap_or_else(|| { fail!("CARGO_BIN_PATH wasn't set. Cannot continue running test") }) diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index cd29b9903..318776140 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1,10 +1,10 @@ -use std::io::fs; +use std::io::{fs, TempDir}; use std::os; use std::path; use std::str; use support::{ResultTest, project, execs, main_file, basic_bin_manifest}; -use support::{COMPILING, RUNNING, cargo_dir}; +use support::{COMPILING, RUNNING, cargo_dir, ProjectBuilder}; use hamcrest::{assert_that, existing_file}; use cargo; use cargo::util::{process, realpath}; @@ -69,7 +69,8 @@ test!(cargo_compile_with_invalid_version { }) test!(cargo_compile_without_manifest { - let p = project("foo"); + let tmpdir = TempDir::new("cargo").unwrap(); + let p = ProjectBuilder::new("foo", tmpdir.path().clone()); assert_that(p.cargo_process("cargo-build"), execs() -- 2.30.2